﻿'© 2004 - 2009 ActiveModules, Inc. All Rights Reserved
Imports Microsoft.ApplicationBlocks.Data
Namespace DotNetNuke.Modules.ActiveForums.Data
    Public Class Profiles
        Inherits DataConfig
        Public Sub Profiles_Create(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal UserId As Integer)
            SqlHelper.ExecuteNonQuery(_connectionString, dbPrefix & "UserProfiles_Create", PortalId, -1, UserId)
        End Sub
        Public Sub Profiles_UpdateActivity(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal UserId As Integer)
            SqlHelper.ExecuteNonQuery(_connectionString, dbPrefix & "UserProfiles_UpdateActivity", PortalId, ModuleId, UserId)
        End Sub
        Public Function Profiles_GetUsersOnline(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal Interval As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(_connectionString, dbPrefix & "UserProfiles_GetUsersOnline", PortalId, ModuleId, Interval), IDataReader)
        End Function
        Public Function Profiles_Get(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal UserId As Integer) As IDataReader
            Return SqlHelper.ExecuteReader(_connectionString, dbPrefix & "UserProfiles_Get", PortalId, -1, UserId)
        End Function
        Public Sub Profiles_Save(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal UserId As Integer, ByVal TopicCount As Integer, ByVal ReplyCount As Integer, ByVal ViewCount As Integer, ByVal AnswerCount As Integer, ByVal RewardPoints As Integer, ByVal UserCaption As String, ByVal Signature As String, ByVal SignatureDisabled As Boolean, ByVal TrustLevel As Integer, ByVal AdminWatch As Boolean, ByVal AttachDisabled As Boolean, ByVal Avatar As String, ByVal AvatarType As Integer, ByVal AvatarDisabled As Boolean, ByVal PrefDefaultSort As String, ByVal PrefDefaultShowReplies As Boolean, ByVal PrefJumpLastPost As Boolean, ByVal PrefTopicSubscribe As Boolean, ByVal PrefSubscriptionType As Integer, ByVal PrefUseAjax As Boolean, ByVal PrefBlockAvatars As Boolean, ByVal PrefBlockSignatures As Boolean, ByVal PrefPageSize As Integer, ByVal Yahoo As String, ByVal MSN As String, ByVal ICQ As String, ByVal AOL As String, ByVal Occupation As String, ByVal Location As String, ByVal Interests As String, ByVal WebSite As String, ByVal Badges As String)
            SqlHelper.ExecuteNonQuery(_connectionString, dbPrefix & "UserProfiles_Save", PortalId, -1, UserId, TopicCount, ReplyCount, ViewCount, AnswerCount, RewardPoints, UserCaption, Signature, SignatureDisabled, TrustLevel, AdminWatch, AttachDisabled, Avatar, AvatarType, AvatarDisabled, PrefDefaultSort, PrefDefaultShowReplies, PrefJumpLastPost, PrefTopicSubscribe, PrefSubscriptionType, PrefUseAjax, PrefBlockAvatars, PrefBlockSignatures, PrefPageSize, Yahoo, MSN, ICQ, AOL, Occupation, Location, Interests, WebSite, Badges)
        End Sub
        Public Function Profiles_GetStats(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal Interval As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(_connectionString, dbPrefix & "UserProfiles_Stats", PortalId, ModuleId, Interval), IDataReader)
        End Function
        Public Function Profiles_MemberList(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal MaxRows As Integer, ByVal RowIndex As Integer, ByVal Filter As String) As IDataReader
            'Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "activeforums_UserProfiles_Members", PortalId, MaxRows, RowIndex, Filter), IDataReader)
            Return CType(SqlHelper.ExecuteReader(_connectionString, dbPrefix & "UserProfiles_List", PortalId, ModuleId, MaxRows, RowIndex, Filter), IDataReader)
        End Function
        Public Sub Profile_UpdateTopicCount(ByVal PortalId As Integer, ByVal UserId As Integer)
            Dim sSql As String = "UPDATE " & dbPrefix & "UserProfiles SET TopicCount = ISNULL((Select Count(t.TopicId) from "
            sSql &= dbPrefix & "Topics as t INNER JOIN "
            sSql &= dbPrefix & "Content as c ON t.ContentId = c.ContentId AND c.AuthorId = @AuthorId INNER JOIN "
            sSql &= dbPrefix & "ForumTopics as ft ON ft.TopicId = t.TopicId INNER JOIN "
            sSql &= dbPrefix & "Forums as f ON ft.ForumId = f.ForumId "
            sSql &= "WHERE c.AuthorId = @AuthorId AND t.IsApproved = 1 AND t.IsDeleted=0 AND f.PortalId=@PortalId),0) "
            sSql &= "WHERE UserId = @AuthorId AND PortalId = @PortalId"
            sSql = sSql.Replace("@AuthorId", UserId.ToString)
            sSql = sSql.Replace("@PortalId", PortalId.ToString)
            SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, sSql)


        End Sub

    End Class
End Namespace